var util = require('../../../utils/utils.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    movie: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var movieId = options.id;
    var url = app.globalData.doubanDomain + '/v2/movie/subject/'+movieId;
    console.log("url="+url);
    util.http(url, this.processDoubanData);
  },
  processDoubanData:function(data){
    console.log(data);
    if(!data)return;
    var director = {
      avatar : "",
      name : "",
      id : ""
    }

    if (data.directors[0] != null){
      
      if (data.directors[0].avatars != null){
        director.avatar = data.directors[0].avatars.large;
      }
      
      director.name = data.directors[0].name;
      director.id = data.directors[0].id;
     
    }



    var movie = {
      movieImg: data.images ? data.images.large : "",
      country :data.countries[0],
      title: data.title,
      originalTitle: data.original_title,
      wishCount: data.wish_count,
      commentCount: data.comments_count,
      stars: util.convertToStarsArray(data.rating.stars),
      genres: data.genres.join("、"),
      year: data.year,
      score: data.rating.average,
      director: director,
      casts: util.convertToCastString(data.casts),
      castsInfo: util.convertToCastInfos(data.casts),
      summary: data.summary
    }

    this.setData({
      movie: movie
    });
  }
})